package com.woniuxy.untis;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;

import javax.websocket.DecodeException;
import javax.websocket.Decoder;
import javax.websocket.EndpointConfig;

public class MessageDecoder implements Decoder.Text<ChatMessage> {

    @SneakyThrows
    @Override
    public ChatMessage decode(String s) throws DecodeException {
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(s,ChatMessage.class);
    }

    @Override
    public boolean willDecode(String s) {
        return true;
    }

    @Override
    public void init(EndpointConfig endpointConfig) {

    }

    @Override
    public void destroy() {

    }
}
